﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "logger.h"
#include "formlog.h"
#include "widgettcpcfg.h"
#include "formrequester.h"
#include "tcprequester.h"
#include "serialportrequester.h"
#include "tcpresponder.h"
#include "zmqrequester.h"


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    qInstallMessageHandler(Logger::CustomMessageHandler);

    initTcp();
    initSerialPort();
    initZmq();
}

void MainWindow::initTcp()
{
    TcpRequester *req=new TcpRequester(this);
    req->setName("tcp_requester");
    FormRequester *w=new FormRequester(this);
    w->setComm(req);
    ui->tabWidget->addTab(w,"tcp_requester");
}

void MainWindow::initSerialPort()
{
    SerialPortRequester *req=new SerialPortRequester(this);
    req->setName("serialport_requester");
    FormRequester *w=new FormRequester(this);
    w->setComm(req);
    ui->tabWidget->addTab(w,"serialport_requester");
}

void MainWindow::initZmq()
{
    ZmqRequester *req=new ZmqRequester(this);
    req->setName("zmq_requester");
    FormRequester *w=new FormRequester(this);
    w->setComm(req);
    ui->tabWidget->addTab(w,"zmq_requester");
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_actionLog_triggered()
{
    static FormLog frm;
    frm.show();
}
